package com.qj.yantaishan.controller;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.ProductToProperty;
import com.qj.yantaishan.service.IProductToPropertyService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 商品关联属性idController
 * 
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/ProductToProperty")
public class ProductToPropertyController extends BaseController
{
    private String prefix = "yantaishan/ProductToProperty";

    @Autowired
    private IProductToPropertyService productToPropertyService;

    @RequiresPermissions("yantaishan:property:view")
    @GetMapping()
    public String property()
    {
        return prefix + "/property";
    }

    /**
     * 查询商品关联属性id列表
     */
    @RequiresPermissions("yantaishan:property:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProductToProperty productToProperty)
    {
        startPage();
        List<ProductToProperty> list = productToPropertyService.selectProductToPropertyList(productToProperty);
        return getDataTable(list);
    }

    /**
     * 导出商品关联属性id列表
     */
    @RequiresPermissions("yantaishan:property:export")
    @Log(title = "商品关联属性id", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductToProperty productToProperty)
    {
        List<ProductToProperty> list = productToPropertyService.selectProductToPropertyList(productToProperty);
        ExcelUtil<ProductToProperty> util = new ExcelUtil<ProductToProperty>(ProductToProperty.class);
        return util.exportExcel(list, "商品关联属性id数据");
    }

    /**
     * 新增商品关联属性id
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品关联属性id
     */
    @RequiresPermissions("yantaishan:property:add")
    @Log(title = "商品关联属性id", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProductToProperty productToProperty)
    {
        return toAjax(productToPropertyService.insertProductToProperty(productToProperty));
    }

    /**
     * 修改商品关联属性id
     */
    @RequiresPermissions("yantaishan:property:edit")
    @GetMapping("/edit/{pigcmsId}")
    public String edit(@PathVariable("pigcmsId") Integer pigcmsId, ModelMap mmap)
    {
        ProductToProperty productToProperty = productToPropertyService.selectProductToPropertyByPigcmsId(pigcmsId);
        mmap.put("productToProperty", productToProperty);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品关联属性id
     */
    @RequiresPermissions("yantaishan:property:edit")
    @Log(title = "商品关联属性id", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProductToProperty productToProperty)
    {
        return toAjax(productToPropertyService.updateProductToProperty(productToProperty));
    }

    /**
     * 删除商品关联属性id
     */
    @RequiresPermissions("yantaishan:property:remove")
    @Log(title = "商品关联属性id", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(productToPropertyService.deleteProductToPropertyByPigcmsIds(ids));
    }
}
